<!--  -->
<template>
  <div style="padding: 15px 30px">
    <!-- <el-dialog title="提审" :visible.sync="dialogShow" width="65%" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false"> -->
    <div class="font-size-16 font-weight-700 padding-bottom-10">地下停车场和立体停车楼({{ underList.length }})</div>
    <el-descriptions :column="2" v-for="(item, key) in underList" :key="key + '+'" class="border-bottom-F2F2F2 margin-bottom-10 padding-left-right-10">
      <el-descriptions-item label="停车场名称">{{ item.parkName }}</el-descriptions-item>
      <el-descriptions-item label="功能分区">{{ GetObjBykey(areaList, 'primaryKey', item.functionalPartition).partitionName }}</el-descriptions-item>
      <!-- <el-descriptions-item label="所在楼层">{{ GetObjBykey(GetObjBykey(areaList, 'primaryKey', item.functionalPartition).floors, 'floorKey', item.locationFloor).floorName }}</el-descriptions-item> -->
      <el-descriptions-item label="停车场编码">{{ item.parkCode }}</el-descriptions-item>
      <el-descriptions-item label="总车位数">{{ item.parkNum }}</el-descriptions-item>
      <el-descriptions-item label="已售车位数">{{ item.ccParkNum }}</el-descriptions-item>
      <el-descriptions-item label="建筑面积">{{ item.buidArea }}</el-descriptions-item>
      <el-descriptions-item label="停车场图片">
        <el-link :type="item.parkImg ? 'primary' : ''" @click="viewImg(item)">查看</el-link>
      </el-descriptions-item>
      <el-descriptions-item label="相关文件">
        <el-link :type="item.businessAttachment && item.businessAttachment.length ? 'primary' : ''" @click="seaFile(item)">查看</el-link>
      </el-descriptions-item>
    </el-descriptions>

    <div class="font-size-16 font-weight-700 padding-bottom-10">地面停车场({{ onList.length }})</div>
    <el-descriptions :column="2" v-for="(item, key) in onList" :key="key" class="border-bottom-F2F2F2 margin-bottom-10 padding-left-right-10">
      <el-descriptions-item label="停车场名称">{{ item.parkName }}</el-descriptions-item>
      <el-descriptions-item label="停车场位置描述">{{ item.parkLocationDesc }}</el-descriptions-item>
      <el-descriptions-item label="停车场编码">{{ item.parkCode }}</el-descriptions-item>
      <el-descriptions-item label="总车位数">{{ item.parkNum }}</el-descriptions-item>
      <el-descriptions-item label="已售车位数">{{ item.ccParkNum }}</el-descriptions-item>
      <el-descriptions-item label="建筑面积">{{ item.buidArea }}</el-descriptions-item>
      <el-descriptions-item label="停车场图片">
        <el-link :type="item.parkImg ? 'primary' : ''" @click="viewImg(item)">查看</el-link>
      </el-descriptions-item>
      <el-descriptions-item label="相关文件">
        <el-link :type="item.businessAttachment && item.businessAttachment.length ? 'primary' : ''" @click="seaFile(item)">查看</el-link>
      </el-descriptions-item>
    </el-descriptions>

    <div class="t-right padding-top-15">
      <!-- <el-button v-if="$route.query.IsUpcoming" type="primary" size="mini" @click="apisuccessAudit">审批通过</el-button> -->
      <!-- <el-button size="small" @click="hideDialog">取 消</el-button> -->
      <el-button v-if="!$route.query.processWorkId" size="small" type="primary" @click="approveFn">提 审</el-button>
    </div>
    <!-- </el-dialog> -->
    <ApproveInfo v-if="$route.query.processWorkId"></ApproveInfo>

    <el-dialog title="附件" :visible.sync="fileDialog" width="800px" :close-on-click-modal="false" :close-on-press-escape="false">
      <div v-for="(item, index) in fileList" :key="index" class="margin-bottom-15">
        附件{{ index + 1 }}：<el-link type="primary" @click="uploadLoad(item.fileUrl)">{{ item.fileTitle }}</el-link>
      </div>
    </el-dialog>

    <el-image-viewer v-if="imgViewerVisible" :on-close="closeImgViewer" :url-list="imgList" />
  </div>
</template>
<script>
  import { apiBuildingInfo } from '../../../../api/building';
  import { requestTips, askDialog } from '../../../../assets/util';
  import ApproveInfo from '../approveInfo.vue';
  import projectInfoApi from '../../../../api/projectInfo';
  import { apisuccessAudit, apifailAudit } from '../../../../api/common';
  export default {
    components: {
      ApproveInfo,
      'el-image-viewer': () => import('element-ui/packages/image/src/image-viewer'),
    },
    props: {
      pageType: {
        type: String,
        default: '',
      },
    },
    data() {
      return {
        areaList: [],
        dialogShow: false,
        fileDialog: false,
        onList: [],
        underList: [],
        fileList: [],
        imgViewerVisible: false,
        imgList: [],
        projectKey:this.$route.query.projectKey || localStorage.getItem("projectKey")
      };
    },

    mounted() {
      this.getInfo();
    },

    methods: {
      GetObjBykey(list, key, value) {
        if (!list) return {};
        let obj = {};
        obj = list.find(res => {
          return res[key] == value;
        });
        return obj ? obj : {};
      },
      apisuccessAudit() {
        apisuccessAudit({
          floorKey: this.$route.query.floorKey,

          projectKey: this.projectKey,
          systemType: this.$route.query.systemType,
          workId: this.$route.query.workId,
          workType: this.$route.query.workType,
        }).then(res => {
          if (res.success) {
            this.$message.success(res.message);
          } else this.$message.warning(res.message);
        });
      },
      async getInfo() {
        this.onList = [];
        this.underList = [];
        let res = await projectInfoApi.apiParkApproInfo({
          workId: this.$route.query.workId,
          projectKey: this.projectKey,
        });
        res.rows.forEach(item => {
          if (item.parkType == 0) {
            this.onList.push(item);
          } else {
            this.underList.push(item);
          }
        });
      },
      approveFn() {
        askDialog('确认提审？', async () => {
          let data = {
            workType: 3,
            projectKey: this.projectKey,
            workId: this.$route.query.workId,
          };
          let res = await projectInfoApi.summitAudit(data);
          requestTips(res, () => {
            if (res.success) {
              this.$message.success(res.message);
              window.location.replace(location.href + '&processWorkId=' + this.$route.query.workId);
            } else {
              this.$message.warning(res.message)
            };
          });
        });
      },
      seaFile(data) {
        if (!data.businessAttachment || data.businessAttachment.length == 0) {
          this.$message.warning('暂无文件');
          return;
        }
        this.fileList = data.businessAttachment;
        this.fileDialog = true;
      },
      hideDialog() {
        this.dialogShow = false;
      },
      //下载
      uploadLoad(url) {
        let a = document.createElement('a');
        a.style.display = 'none';
        a.href = url;
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
      },
      viewImg(item) {
        if (!item.parkImg) {
          this.$message.warning('暂无图片');
          return;
        }

        this.imgList = [item.parkImg];
        this.imgViewerVisible = true;
      },
      closeImgViewer() {
        this.imgViewerVisible = false;
      },
    },
  };
</script>
<style lang="scss" scoped></style>
